/**
 * @文件名 DWRSessionService.java
 * @包名 com.ykfk.cngrain.tbw
 * @说明 DWRSession过期处理
 * @作者 wdfang
 * @时间 2013-1-30 上午12:29:53
 * @版本 V1.0
 */ 
package com.ykfk.cngrain.tbw;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.directwebremoting.ScriptBuffer;
import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;
import org.directwebremoting.extend.Calls;
import org.directwebremoting.extend.Replies;
import org.directwebremoting.impl.DefaultRemoter;
import org.directwebremoting.proxy.dwr.Util;

/**
 * 
 * @类名 DWRSessionService
 * @描述 DWRSession过期处理
 * @作者 wdfang
 * @日期 2013-1-30 上午12:29:53 
 * ========修改日志=======
 * 
 */
public class DWRSessionService extends DefaultRemoter {
	/**
	 * 
	 * @名称 execute
	 * @描述 DWR执行方法
	 * @参数 @param calls
	 * @返回值 Replies
	 * @作者 wdfang
	 * @时间 2013-1-30 上午12:33:38
	 */
	@Override
	public Replies execute(Calls calls) {
		Replies replies = null;
		HttpSession session = WebContextFactory.get().getSession();
		HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
		String uri = request.getRequestURI();

		if (uri.contains("tradeDateEques") || uri.contains("getUserName")
				|| uri.contains("checkMangRole") || uri.contains("existSms")
				|| uri.contains("Share_ceng") || uri.contains("getlockstate")) {
			replies = super.execute(calls);
		} else {
			Object sc = session.getAttribute("tlrno");
			if (sc == null) {
				logOut();
				replies = super.execute(new Calls());
			} else {
				replies = super.execute(calls);
			}
		}
		return replies;
	}
	/**
	 * 
	 * @名称 logOut
	 * @描述 session过期后退出，对应页面上logOut()js函数
	 * @参数 
	 * @返回值 void
	 * @作者 wdfang
	 * @时间 2013-1-30 上午12:35:16
	 */
	private void logOut() {
		WebContext wct = WebContextFactory.get();
		Util utilThis = new Util(wct.getScriptSession());
		utilThis.addScript(new ScriptBuffer("logout()"));
	}
}
